Fix global ref lifecycle for verify and missing-CRL callbacks#369
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes JNI global-ref lifecycle issues by making the verify callback reference per-WOLFSSL_CTX (via ex_data) and adjusting missing-CRL callback cleanup to only happen at library unload.
Changes:
- Store per-context verify callback
jobjectinWOLFSSL_CTX ex_dataand resolve it inNativeVerifyCallback(). - Move missing-CRL callback global-ref cleanup to
JNI_OnUnload()via new cleanup helpers. - Add a JUnit test covering multi-context
setVerify()install/replace/unregister/free flows.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/com/wolfssl/test/WolfSSLContextTest.java | Adds a multi-context setVerify() lifecycle test intended to surface global-ref mishandling. |
| native/com_wolfssl_globals.h | Declares the ex_data index global and new cleanup helper prototypes. |
| native/com_wolfssl_WolfSSLSession.c | Adds JNI_OnUnload() cleanup for the process-global session missing-CRL callback; stops freeing it in freeSSL(). |
| native/com_wolfssl_WolfSSLContext.c | Moves verify callback storage to per-CTX ex_data, adds CTX-level missing-CRL cleanup helper, and adjusts freeContext() cleanup. |
| native/com_wolfssl_WolfSSL.c | Allocates the ex_data index during WolfSSL_init() and calls cleanup helpers in JNI_OnUnload(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8e1a905 to
b0b710f
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #369
Scan targets checked: wolfssljni-bugs, wolfssljni-src
No new issues found in the changed files. ✅
b0b710f to
3935575
Compare
3935575 to
c2fcdf1
Compare
Member
Author
|
Force pushed to add a mutex around the missing CRL callback. |
rlm2002
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a JNI callback global-reference lifecycle bug (F-1024) where
setVerify()/setCRLCb()on oneWolfSSLContextorWolfSSLSessioncould delete a callback ref another thread was about to dereference inside the corresponding native callback.Verify callback
staticto per-WOLFSSL_CTXex_data, allocated inJava_com_wolfssl_WolfSSL_init()afterwolfSSL_Init().NativeVerifyCallback()resolves the cb viastore -> ssl -> ctx -> ex_data, so each context fires its own user callback.g_verifyCbMutexplusNativeVerifyCbLock/Unlockhelpers.Missing-CRL callbacks
CbMissingCRLhas no SSL/CTX argument), but addsg_crlCbMutexshared acrossg_crlCtxCbIfaceObjandg_crlCbIfaceObjto close the same race forsetCRLCb()on bothWolfSSLContextandWolfSSLSession.setCRLCb(null)now also callswolfSSL_(CTX_)SetCRL_Cb(..., NULL)so the native cb is unregistered when the Java side clears it.freeContext()/freeSSL(); onlysetCRLCb()overwrites them andJNI_OnUnload()releases them via newNativeWolfSSLContextCleanup()/NativeWolfSSLSessionCleanup()helpers.Behavior changes
NativeVerifyCallbacknow fails closed (returns 0, handshake fails) when no Java callback is registered on the connection'sWOLFSSL_CTX. Previously the process-global verify cb was invoked across all contexts.NativeMissingCRLCallback/NativeCtxMissingCRLCallbacknow drop silently when no Java cb is registered. Previously aWolfSSLException/WolfSSLJNIExceptionwould be thrown back into native wolfSSL.Tests
test_WolfSSLContext_setVerifyMultipleContexts- install / replace / unregister / interleaved-free lifecycle across two contexts.test_WolfSSLContext_setVerifyHandshakeRouting- handshake on two client CTXs asserts each cb fires only for its own handshake.test_WolfSSLContext_setCRLCbMultipleContexts- parallel lifecycle test for bothWolfSSLContext.setCRLCbandWolfSSLSession.setCRLCb, asserts no spurious cb fires across contexts.Fixes F-1024.